home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AmigActive 10
/
AACD 10.iso
/
AACD
/
Utilities
/
GOCR
/
src
/
pgm2asc.h
< prev
next >
Wrap
C/C++ Source or Header
|
2000-05-23
|
6KB
|
153 lines
#ifndef PGM2ASC_H
#define PGM2ASC_H 1
#include "pnm.h"
#define Uint unsigned int
#define Uchar unsigned char
#define MAXlines 1024
struct tlines {
int num;
int dy; /* offset for straight/skew lines dy(x+px) */
int m1[MAXlines], /* start of line = upper bound of 'A' */
m2[MAXlines], /* upper bound of 'e' */
m3[MAXlines], /* lower bound of 'e' = baseline */
m4[MAXlines]; /* stop of line = lower bound of 'q' */
int x0[MAXlines],
x1[MAXlines]; /* left and right border */
};
extern struct tlines lines;
// ---------------------------------------------------------------------
// list of letter boxes (root+end or end==root)
// ---------------------------------------------------------------------
struct box { // this structure should contain all pixel infos of a letter
int x0,x1,y0,y1,x,y,dots; // xmin,xmax,ymin,ymax,reference-pixel,i-dots
struct box *next; // points to next box
struct box *pre; // points to predecessor (right word?)
char c; // detected char '_' means unknown, '@' = picture
int num; // same nummer = same char
int line; // line number (points to struct tlines lines)
int m1,m2,m3,m4; // m2 = upper boundary, m3 = baseline
// planed: sizeof hole_1, hole_2, certainty (run1=100%,run2=90%,etc.)
pix *p; // pointer to pixmap (v0.2.5)
};
extern struct box *box1,*box2; // root, temp
struct environment { // public for all
int cs; // critical value (pixel<cs => black pixel)
int avX,avY; // average X,Y
pix *p; // pixelmap 8bit gray
};
extern struct environment env;
int in_str(char c, char *s); /* return 0 or pos+1 */
// ------------------------ end list-funcs --------------------------
// test if pixel marked?
int marked(pix &p, int x, int y); // ret: 0=not_marked
// test if pixel --- later with error-correction
int pixel(pix &p, int x, int y); // ret: pixel-color (without marks)
void out_b(pix b, int x0, int y0, int dx, int dy, int cs );
void out_x(box *px);
// ------------------------ feature extraction -----------------
#define AT 7 // mark
#define M1 1 // mark
#define UP 1 // up // look at loop, do not change!
#define DO 2 // down
#define RI 3 // right
#define LE 4 // left
#define ST 7 // stop
// -------------------------------------------------------------
// detect maximas in of line overlapps (return in %) and line koord
#define HOR 1 // horizontal
#define VER 2 // vertikal
#define RIS 3 // rising=steigend
#define FAL 4 // falling=fallend
struct tline {
int x0,y0,x1,y1; // middle points
};
extern struct tline line;
// kalkulate the overlapp of the line (0-1) with black points
// by rekursiv bisection
// (evl. Fehlertoleranz mit pixel in Umgebung dx,dy suchen) (umschaltbar) ???
// MidPoint Line Algorithm (Bresenham) Foley: ComputerGraphics better?
// gerade y=dy/dx*x+b, implizit d=F(x,y)=dy*x-dx*y+b*dx=0
// incrementell y(i+1)=m*(x(i)+1)+b, F(x+1,y+1)=f(F(x,y))
int get_line(int x0, int y0, int x1, int y1, pix p, int cs, int ret);
int get_line2(int x0, int y0, int x1, int y1, pix p, int cs, int ret);
// look for white 0x02 or black 0x01 dots (0x03 = white+black)
char get_bw(int x0, int x1, int y0, int y1,
pix p, int cs,int mask);
// look for black crossing a line x0,y0,x1,y1
// follow line and count crossings ([white]-black-transitions)
int num_cross(int x0, int x1, int y0, int y1,
pix p, int cs);
// -------------------------------------------------------------
// mark edge-points
// - first move forward until b/w-edge
// - more than 2 pixel?
// - loop around
// - if forward pixel : go up, rotate right
// - if forward no pixel : rotate left
// - stop if found first 2 pixel in same order
// mit an rechter-Wand-entlang-gehen strategie
// --------------------------------------------------------------
// turmite game: inp: start-x,y, regel r_black=UP,r_white=RIght until border
// out: last-position
// Zaehle dabei, Schritte,Sackgassen,xmax,ymax,ro-,ru-,lo-,lu-Ecken
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// SEHR GUTE IDEE VON MIR!!! KI-Methode!!! patentierbar?
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
void turmite(pix &p, int &x, int &y,
int x0, int x1, int y0, int y1, int cs, int rw, int rb);
// test if points are connected via t-pixel (rekursiv!)
int joined(pix &p, int x0, int y0, int x1, int y1, int cs);
// move from x,y to direction r until pixel or l steps
// return number of steps
int loop(pix &p, int x, int y, int l, int cs, int col, int r);
// mark recursiv if no-pixel-neighbours=0 connected with (x,y)
// better with neighbours of same color (more general) ???
// (&~7)-pixmap, start-point, critical_value, mark
// mark neighbouring pixel of same color, return number
int mark_nn(pix &p, int x, int y, int &cs, int r);
void frame_nn(pix &p, int x, int y,
int &x0, int &x1, int &y0, int &y1, // enlargeframe
int cs, int r);
// --- copy part of pix p into new pix b ---- len=10000
int copybox( pix p, int x0, int y0, int dx, int dy, pix *b, int len);
// look for white holes surrounded by black points
// at moment white point with black in all for directions
int num_hole(int x0, int x1, int y0, int y1, pix p, int cs);
// count for black nonconnected objects --- used for i,auml,ouml,etc.
int num_obj(int x0, int x1, int y0, int y1, pix p, int cs);
int distance( pix p1, box *box1, // box-frame
pix p2, box *box2, int cs);
// call the OCR engine ;)
//char whatletter(box *box1,int cs);
// test if char c in string cset
int strc(char c, char *cset);
#endif